import * as requestApi from '../../../packages/shared-api/src/index'   //第1运行 - 获取备用域名
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { useGlobalStore } from './stores/global'
import getLinkParams from './request/getLinkParams' //第2运行 - 获取链接参数
import App from './App.vue'
import router from './router'
import './assets/main.css'
console.log('【项目主入口main.ts --->requestApi：】', requestApi)
console.log('【项目主入口main.ts --->getLinkParams：】', getLinkParams)

async function initializeApp() {    
    await requestApi.config.initDomainURL()  // 等待配置初始化
    const app = createApp(App)
    const pinia = createPinia()
    pinia.use(piniaPluginPersistedstate)  // 注册持久化插件
    app.use(pinia)

    // 保存到全局 store
    const globalStore = useGlobalStore(pinia) as ReturnType<typeof useGlobalStore>
    globalStore.setParams({ ...getLinkParams, baseURL: requestApi.config.baseURL })
    
    app.use(router).mount('#app')
}

initializeApp()
